﻿@model MvcApplication5.Models.CreateModel
@{
    ViewBag.Title = "Bài viết mới";
    Layout = "~/Views/News/AdminLayout.cshtml";
}

<h2>Bài viết mới</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    function validateForm()
    {
        var x=document.forms["form1"]["News.Title"].value;
        if (x==null || x=="")
        {
            alert("Bạn chưa nhập tiêu đề tin");
            return false;
        }
}
</script>

@using (Html.BeginForm(null, null, FormMethod.Post, new { name = "form1", onsubmit = "return validateForm();" })){
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>News</legend>
        <div class="editor-label">
            Chuyên mục:
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(m => m.News.CategoryId, new SelectList(Model.categoryList, "CategoryId", "Name"))
            @Html.ValidationMessageFor(model => model.News.CategoryId)
        </div>        
        <div class="editor-label">
            Tiêu đề:
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.News.Title)
            @Html.ValidationMessageFor(model => model.News.Title)
        </div>

        <div class="editor-label">
            Ảnh đại diện:
        </div>
        <div class="editor-field">                      
            <input runat="server" id="News_Image" name="News.Image" style="WIDTH: 308px" type="file"/>
            @Html.ValidationMessageFor(model => model.News.Image)
        </div>
        <div class="editor-label">
            Tóm tắt:
        </div>
        <div class="editor-field">            
            <textarea id="News_Summary" name="News.Summary" rows="5" cols="70"></textarea>
        </div>
        <div class="editor-label">
            Nội dung bài viết:
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.News.Content, new { @id = "ckeContent" })
            <script type="text/javascript">
                CKEDITOR.replace("ckeContent");
            </script>
            @Html.ValidationMessageFor(model => model.News.Content)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.News.Author)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(m => m.News.AuthorId, new SelectList(Model.authorList, "AuthorId", "Name"),"")
            @Html.ValidationMessageFor(model => model.News.AuthorId)
        </div>        
        @*<div class="editor-field">
            <select name="sometext" multiple="multiple" style="width:300px; height:100px;">
                @if (Model.relatedList.Count() != 0)
                {
                    foreach (var item in Model.News.RelatedDetails)
                    {
                        <option>@item.RelatedDetailsId</option>
                    }
                }                    
            </select>
        </div>*@
        <input type="hidden" id="News_level" name="News.level" value="0" />
        <input type="hidden" id="News_AccountId" name="News.AccountId" value="@int.Parse(Session["UserId"].ToString())" />
        <input type="hidden" id="News_LastModifiedDate" name="News.LastModifiedDate" value="@DateTime.Now" />
        <input type="hidden" id="UserType" name="UserType" value="@ViewBag.UserType" />
        <p>
            <input type="submit" value="Lưu lại" />            
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "TempList")
</div>
